yjx.controller('supportDetailController',['$rootScope','$scope','$stateParams','$timeout','$location','$fetch','modalService','wxShareService','$locals',function ($rootScope,$scope,$stateParams,$timeout,$location,$fetch,modalService,wxShareService,$locals) {

    var api = '/support/getSupport',
        id = $stateParams.id,
        pendingEventId = $stateParams.pendingEventId;
         $scope.forwardId = $stateParams.forwardId;
    $rootScope.tabCtrlName = $rootScope.tabCtrlNameArr[2]


    $rootScope.wxShareSuc = function(){
        /*调用后端记录转发次数的分享*/
       //alert($rootScope.identity )
        if($rootScope.identity == 1) {
            //alert("分享+1")
            $fetch.fetch(
                '/share/recordRelay/content/times',
                {
                    params:{
                        userId:$rootScope.userId,
                        contentId:id,
                        pendingEventId:pendingEventId,
                        type:1
                    },
                    cache:false,
                    //type:'POST'
                }
            ).then(function(data){
                    console.log(data)
                    //alert(data);
                }).catch(function(e){
                    //alert("报错啦==============");
                    modalService.mainMsgError(e.msg)
                })
        }
    }
    function getResource() {
        $fetch.fetch(
            api,
            {
                params: {
                    id:id
                },
                cache:false
            }
        ).then(function (data) {
                $timeout(function () {
                    if(data && data.rows){
                        $scope.surDetail = data.rows[0];
                    }
                    /*获取微信转发配置*/
                    //$rootScope.wxTitle = $scope.surDetail.title;
                    $rootScope.wxDesc = $scope.surDetail.title;
                    $rootScope.wxImg= $scope.surDetail.avatar;
                    /*android分享链接添加#时自带参数会被微信自动添加的form等参数截掉  原因未知*/
                    if ($rootScope.isAndroid) {
                        var linkhead = "http://www.genetuan.com/"
                    } else {
                        var linkhead = "http://www.genetuan.com/#/"
                    }
                    if($rootScope.identity == 1)  {
                        if ($rootScope.isAndroid) {
                            $rootScope.link =  linkhead+"?url=surDetail&id="+id+"&forwardId="+$rootScope.userId+"&pendingEventId="+pendingEventId;
                            wxShareService.getConfig('',['onMenuShareAppMessage','hideMenuItems']);
                        }else{
                            $rootScope.link =  linkhead+"surDetail?id="+id+"&forwardId="+$rootScope.userId+"&pendingEventId="+pendingEventId;
                            wxShareService.getConfig('',['onMenuShareAppMessage','hideMenuItems']);
                        }
                        //$location.search({'id':id,'forwardId':$rootScope.userId,'pendingEventId':pendingEventId});/*将url改变成为要转发出去的url */
                    }else{
                        if ($rootScope.isAndroid) {
                            $rootScope.link =  linkhead+"?url=surDetail&id="+id;
                            wxShareService.getConfig('',['onMenuShareAppMessage','hideMenuItems']);
                        }else{
                            $rootScope.link =  linkhead+"surDetail?id="+id;
                            wxShareService.getConfig('',['onMenuShareAppMessage','hideMenuItems']);
                        }
                    }
                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }

   function addClick(){
       $fetch.fetch(
           '/update/content/clickTimes',
           {
               params:{contentId:id},
               cache:false
           }
       ).then(function(data){

           }).catch(function(e){

           })
   }


    if(id){
        getResource();
        addClick();
    }




    if($scope.forwardId && $scope.forwardId != $rootScope.userId) {
        $fetch.fetch(
            '/user/getBusinessCard',
            {
               params:{
                   id:$scope.forwardId
               }
            }
        ).then(function(data) {
                $timeout(function(){
                    if(data && data.businessCard) {
                        $scope.forward=data.businessCard;
                        //console.log($scope.forward);
                    }
                })
            }).catch(function(e){

            })
    }
    if($scope.forwardId == $rootScope.userId){
        $scope.forward = {
            nickname:$rootScope.user.nickname,
            avatar:$rootScope.user.avatar
        }
    }

    if(!$scope.forwardId && $rootScope.identity!=1){
        angular.element(document.getElementById('surContent')).addClass('surContent2')
    }
}])